/*
 * Created on Apr 4, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package littlecyberwar.control.net;

import java.lang.Thread;
import littlecyberwar.util.*;
import littlecyberwar.ui.*;
import java.net.*;
import java.io.*;
import javax.swing.*;

/**
 * @author Milton  Soong
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class NetHandler {
	
	/**
	 * Create a task for handling incoming traffic, and one that handles outgoing traffic
	 * 
	 * @param socket a socket that's already been created
	 */
	public static void socketCreated(Socket socket) {
		InputStream is=null;
		OutputStream os = null;
		try {
			is = socket.getInputStream();
			os = socket.getOutputStream();
			
		} catch ( IOException ex){
			// !!! Later on put up an error dialog
			ex.printStackTrace();		
		}
		// outgoing must be first...SInce the incoming task will pend 
		setupOutgoingTask(os);
		setupIncomingTask(is);
		return;
	}
	
	private static void setupIncomingTask( InputStream is ){
		IncomingTask it = new IncomingTask(is);
		it.start();
	}
	
	private static void setupOutgoingTask( OutputStream os ){
		OutgoingTask ot = new OutgoingTask(os);
		ot.start();
	}
}
